﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ch01.client.service.web;
using ch01.service.@interface;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace ch01.client
{
    class Program
    {
        static void Main(string[] args)
        {
            ////通过自动生成的代码,去访问服务
            //using (CalculatorServiceClient proxy = new CalculatorServiceClient())
            //{
            //    Console.WriteLine(" x + y = {2} when x = {0} and y = {1}", 11.3, 12.6, proxy.Add(11.3 , 12.6));
            //    Console.WriteLine(" x - y = {2} when x = {0} and y = {1}", 7, 19.54, proxy.Subtract(7, 19.54));
            //    Console.WriteLine(" x * y = {2} when x = {0} and y = {1}", 82.3, 2.64, proxy.Multiply(82.3, 2.64));
            //    Console.WriteLine(" x / y = {2} when x = {0} and y = {1}", 79.65,5.78, proxy.Divide(79.65, 5.78));
            //}

            ////通过指定终结点的方式,去访问服务
            //using (ChannelFactory<ICalculator> channel_factory = new ChannelFactory<ICalculator>(
            //    new WSHttpBinding(), 
            //    "http://127.0.0.1:3721/calculatorservice"
            //    ))
            //{
            //    ICalculator proxy = channel_factory.CreateChannel();
            //    Console.WriteLine(" x + y = {2} when x = {0} and y = {1}", 11.3, 12.6, proxy.Add(11.3, 12.6));
            //    Console.WriteLine(" x - y = {2} when x = {0} and y = {1}", 7, 19.54, proxy.Subtract(7, 19.54));
            //    Console.WriteLine(" x * y = {2} when x = {0} and y = {1}", 82.3, 2.64, proxy.Multiply(82.3, 2.64));
            //    Console.WriteLine(" x / y = {2} when x = {0} and y = {1}", 79.65, 5.78, proxy.Divide(79.65, 5.78));
            //}
            ////通过指定配置的方式,去访问服务
            //using (ChannelFactory<CalculatorService> channel_factory = new ChannelFactory<CalculatorService>("calculatorservice"))
            //{
            //    CalculatorService proxy = channel_factory.CreateChannel();
            //    Console.WriteLine(" x + y = {2} when x = {0} and y = {1}", 11.3, 12.6, proxy.Add(11.3, 12.6));
            //    Console.WriteLine(" x - y = {2} when x = {0} and y = {1}", 7, 19.54, proxy.Subtract(7, 19.54));
            //    Console.WriteLine(" x * y = {2} when x = {0} and y = {1}", 82.3, 2.64, proxy.Multiply(82.3, 2.64));
            //    Console.WriteLine(" x / y = {2} when x = {0} and y = {1}", 79.65, 5.78, proxy.Divide(79.65, 5.78));
            //}

            //通过指定配置的方式,去访问服务(web应用程序)
            using (ChannelFactory<CalculatorService> channel_factory = new ChannelFactory<CalculatorService>("web.calculatorservice"))
            {
                CalculatorService proxy = channel_factory.CreateChannel();
                Console.WriteLine(" x + y = {2} when x = {0} and y = {1}", 11.3, 12.6, proxy.Add(11.3, 12.6));
                Console.WriteLine(" x - y = {2} when x = {0} and y = {1}", 7, 19.54, proxy.Subtract(7, 19.54));
                Console.WriteLine(" x * y = {2} when x = {0} and y = {1}", 82.3, 2.64, proxy.Multiply(82.3, 2.64));
                Console.WriteLine(" x / y = {2} when x = {0} and y = {1}", 79.65, 5.78, proxy.Divide(79.65, 5.78));
            }
        }
    }
}
